/* soft_timer.c/h  3.0 */

#ifndef _SOFT_TIMER_H
#define _SOFT_TIMER_H
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Clock.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/display/Display.h>
#include <ti/display/DisplayExt.h>

#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(driverlib/cpu.h)

#define TIME_BASE_MS		1    //1ms
#define TIMER_NUM           20

typedef void callback(void *argv, uint16_t argc);
typedef struct softTimer {
	uint8_t state;
	uint8_t mode;
	uint32_t match;
	uint32_t period;
	callback *cb;
	void *argv;
	uint16_t argc;
}softTimer;

typedef enum tmrState {
	SOFT_TIMER_STOPPED = 0,
	SOFT_TIMER_RUNNING,
	SOFT_TIMER_TIMEOUT
}tmrState;

typedef enum tmrMode {
	MODE_ONE_SHOT = 0,
	MODE_PERIODIC,
}tmrMode;


#ifdef  USE_FULL_ASSERT
/**
  * @brief  The assert_param macro is used for function's parameters check.
  * @param  expr If expr is false, it calls assert_failed function
  *         which reports the name of the source file and the source
  *         line number of the call that failed.
  *         If expr is true, it returns no value.
  * @retval None
  */
  #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
  void assert_failed(uint8_t* file, uint32_t line);
#else
  #define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */

void tickCnt_Update(void);
uint32_t tickCnt_Get(void);
void softTimer_Init(void);
uint8_t softTimer_GetState(uint16_t id);
void softTimer_Start(uint16_t id, tmrMode mode, uint32_t delay, callback *cb, void *argv, uint16_t argc);
void softTimer_Stop(uint16_t id);
void softTimer_Update(void);


#define TIMER0              0
#define TIMER1              1
#define TIMER2              2
void TIM0_CB(void *argv, uint16_t argc);
void TIM1_CB(void *argv, uint16_t argc);
void TIM2_CB(void *argv, uint16_t argc);

#endif
